如果你多個 Model,用啟動參數來管理,就有點太麻煩了。
這時候你可以使用 model_config.conf
model_config_list {
config {
name: 'saved_model_counter'
base_path: '/models/saved_model_counter/'
model_platform: 'tensorflow'
}
config {
name: 'half_plus_two'
base_path: '/models/half_plus_two/'
model_platform: 'tensorflow'
}
}
然後我們在微調一下,官方提供的 Docker 範例。
# (...略...)
# Set where models should be stored in the container
ENV MODEL_BASE_PATH=/models
RUN mkdir -p ${MODEL_BASE_PATH}
# The only required piece is the model name in order to differentiate endpoints
ENV MODEL_NAME=model
# Create a script that runs the model server so we can use environment variables
# while also passing in arguments from the docker command line
RUN echo '#!/bin/bash \n\n\
tensorflow_model_server --port=8500 --rest_api_port=8501 \
--model_name=${MODEL_NAME} --model_base_path=${MODEL_BASE_PATH}/${MODEL_NAME} \
"$@"' > /usr/bin/tf_serving_entrypoint.sh \
&& chmod +x /usr/bin/tf_serving_entrypoint.sh
ENTRYPOINT ["/usr/bin/tf_serving_entrypoint.sh"]
Docker 原始檔:https://github.com/tensorflow/serving/blob/master/tensorflow_serving/tools/docker/Dockerfile
邏輯上我們要調整的部分有
model_config.conf
也要複製進去model_name
和 model_base_path
都不需要了,我們改用 model_config_file
參數。COPY /models /models
COPY /model_config.conf /model_config.conf
# ENV MODEL_NAME=model
ENV MODEL_CONFIG_FILE=/model_config.conf
RUN echo '#!/bin/bash \n\n\
tensorflow_model_server --port=8500 --rest_api_port=8501 \
--model_config_file=${MODEL_CONFIG_FILE} \
"$@"' > /usr/bin/tf_serving_entrypoint.sh \
&& chmod +x /usr/bin/tf_serving_entrypoint.sh